﻿Chenxin.UI.Income = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/Reports/Income.ashx',
    createSearch: function() {
        return new Chenxin.UI.IncomeSearch({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.GroupReportGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            height:400,
            renderTo: 'divShowBalanceList',
            hasCheckBox: false,
            scope: this,
            id: 'BalanceList',
            title: '运营成交表',
            scope: this,
            cellBorder:true,
			modelId:'DepartId',
			autoLoad:false,
            rowGroupSetting: [
				{ field: 'business', head: '商圈', width: 120, autoCount: true },
				{ field: 'departname', head: '门店', width: 120, autoCount: false }
			],
            columns: {
                M: {
                    head: 'M案',
                    items: {
                        m_point: {
                            head: '套数',
                            width: 80,
                            sortable: true
                        },
                        m_allcommision: {
                            head: '本期收入',
                            width: 100,
                            sortable: true
                        },
                        m_allconsulting: {
                            head: '咨询费',
                            width: 80,
                            sortable: true
                        },
                        m_purecommision: {
                            head: '业绩',
                            width: 80,
                            sortable: true
                        }
                    }
                },
                z: {
                    head: 'Z案',
                    items: {
                        z_point: {
                            head: '套数',
                            width: 80,
                            sortable: true
                        },
                        z_allcommision: {
                            head: '本期收入',
                            width: 100,
                            sortable: true
                        },
                        z_allconsulting: {
                            head: '咨询费',
                            width: 80,
                            sortable: true
                        },
                        z_purecommision: {
                            head: '业绩',
                            width: 80,
                            sortable: true
                        }
                    }
                },
                l: {
                    head: 'L案',
                    items: {
                        l_point: {
                            head: '套数',
                            width: 80,
                            sortable: true
                        },
                        l_allcommision: {
                            head: '本期收入',
                            width: 100,
                            sortable: true
                        },
                        l_allconsulting: {
                            head: '咨询费',
                            width: 80,
                            sortable: true
                        },
                        l_purecommision: {
                            head: '业绩',
                            width: 80,
                            sortable: true
                        }
                    }
                },
                q: {
                    head: 'Q案',
                    items: {
                        q_point: {
                            head: '套数',
                            width: 80,
                            sortable: true
                        },
                        q_allcommision: {
                            head: '本期收入',
                            width: 100,
                            sortable: true
                        },
                        q_allconsulting: {
                            head: '咨询费',
                            width: 80,
                            sortable: true
                        },
                        q_purecommision: {
                            head: '业绩',
                            width: 80,
                            sortable: true
                        }
                    }
                },
                ld: {
                    head: '联动',
                    items: {
                        ld_point: {
                            head: '套数',
                            width: 80,
                            sortable: true
                        },
                        ld_allcommision: {
                            head: '本期收入',
                            width: 100,
                            sortable: true
                        },
                        ld_purecommision: {
                            head: '业绩',
                            width: 80,
                            sortable: true
                        }
                    }
                },
                all: {
                    head: '合计',
                    items: {
                        allcommision: {
                            head: '本期收入',
                            width: 80,
                            sortable: true,
                            renderer: function(val, c, row) {
                            return parseFloat(row.m_allcommision) + parseFloat(row.z_allcommision) + parseFloat(row.l_allcommision) + parseFloat(row.q_allcommision) + parseFloat(row.ld_allcommision);
                            }
                        },
                        purecommision: {
                            head: '业绩',
                            width: 80,
                            sortable: true,
                            renderer: function(val, c, row) {
                            return parseFloat(row.m_purecommision) + parseFloat(row.z_purecommision) + parseFloat(row.l_purecommision) + parseFloat(row.q_purecommision) + parseFloat(row.ld_purecommision);
                            }
                        }
                    }
                }

            }
        });
    }
});

/*
* 查询面板
*/
Chenxin.UI.IncomeSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {

        var _this = this;
        this.combl = new Chenxin.UI.StructComboList();
        var structs = this.combl.comboList;

        return structs;
    },
    afterGetParamJson: function(data) {
        if (!data.ActualDate) {
            this.autoReload = false;
        }
        this.autoReload = true;
    },
    initEvent: function() {
        var date = new Date();
        $("#txtStartTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        $("#txtStartTime").val(date.getFullYear() + '-' + (date.getMonth() + 1) + '-1');


        $("#txtEndTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        if (date.getMonth() + 1 == 12)
            $('#txtEndTime').val(date.getFullYear() + 1 + '-1-1');
        else
            $('#txtEndTime').val(date.getFullYear() + '-' + (date.getMonth() + 2) + '-1');

        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.Income();
});